﻿@namespace BootstrapBlazor.Components
@typeparam TModel
@inherits DialogBase<TModel>

<ValidateForm Model="@Model" OnValidSubmit="@OnValidSubmitAsync">
	@if (BodyTemplate != null)
	{
		@BodyTemplate?.Invoke(Model)
		@if (!IsTracking)
		{
			<div class="row mt-3">
				<div class="col-12">
					@RenderFooter
				</div>
			</div>
		}
	}
	else
	{
		<EditorForm TModel="TModel" Items="Items" ItemChangedType="ItemChangedType" ItemsPerRow="ItemsPerRow" RowType="RowType" LabelAlign="LabelAlign">
			<Buttons>
				@if (!IsTracking)
				{
					@RenderFooter
				}
			</Buttons>
		</EditorForm>
	}
</ValidateForm>
<div class="form-loader" @ref="SpinnerElement">
	<Spinner Color="Color.Primary" />
</div>

@code {
	RenderFragment RenderFooter =>
	@<div class="table-modal-footer">
		<Button Color="Color.Secondary" Icon="fa fa-times" Text="@CloseButtonText" OnClickWithoutRender="@(new Func<Task>(OnClose))" />
		<Button Color="Color.Primary" ButtonType="ButtonType.Submit" Icon="fa fa-save" Text="@SaveButtonText" />
	</div>;
}
